//
//  LLTabBar.m
//  Weibo
//
//  Created by 李灵斌 on 15-1-28.
//  Copyright (c) 2015年 apple. All rights reserved.
//


#import "LLTabBar.h"


@interface LLTabBar()

//@property (nonatomic, strong) NSArray *items;
@property (nonatomic, weak) UIButton *button;

@end

@implementation LLTabBar

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setup];
    }
    return self;
}


- (id)initWithCoder:(NSCoder *)aDecoder{
    
    if (self = [super initWithCoder:aDecoder]) {
        [self setup];
    }
    return self;
}

- (void)setup{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    [self addSubview:button];
    self.button = button;
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    

    CGFloat btnW = self.width / 5;
    CGFloat btnH = self.height;
    int index = 0;
    for (UIView *child in self.subviews) {
        
        if (![child isKindOfClass:[NSClassFromString(@"UITabBarButton") class]]) continue;
        child.width = btnW;
        child.height = btnH;
        child.x = index * btnW;
        if (index >= 2) {
            
            child.x = (index + 1) * btnW;
        }
        index ++;
    }
    
    self.button.centerX = self.width * 0.5;
    self.button.centerY = self.height * 0.5;
    self.button.size = self.button.currentBackgroundImage.size;
}

@end
